#include <iostream>
#include <thread>
#include <functional>
#include <chrono>

class IntReader {
public:
    void beginRead(const std::function<void(int)>& callback){
        std::thread thread([callback](){
            std::this_thread::sleep_for(std::chrono::seconds(2));//模拟耗时操作
            int value = 1;
            callback(value);
        });
        thread.detach();
    }
};

void printInt(){
    IntReader reader;
    reader.beginRead([](int result){
        std::cout << result << std::endl;
    });
}

int main(){
    printInt();
    while(1){};
}